import request from '@/utils/request'

// 查询测试样例列表
export function listMateri(query) {
  return request({
    url: '/result/materi/list',
    method: 'get',
    params: query
  })
}

// 查询测试样例详细
export function getMateri(id) {
  return request({
    url: '/result/materi/' + id,
    method: 'get'
  })
}

// 新增测试样例
export function addMateri(data) {
  if(data){
    data.freturnsituation = "staUnReturned";
    data.fiscompletematerial = "是";
    if(data.ffinishedtime){
      data.fissuedstate = "staHandled";
    }else{
      data.fissuedstate = "staHandling";
    }
    data.fmaterialsupplydate = data.ffinishedtime;
  }
  return request({
    url: '/result/materi',
    method: 'post',
    data: data
  })
}

// 修改测试样例
export function updateMateri(data) {
  if(data.ffinishedtime){
    data.fissuedstate = "staHandled";
  }else{
    data.fissuedstate = "staHandling";
  }
  data.fmaterialsupplydate = data.ffinishedtime;
  return request({
    url: '/result/materi',
    method: 'put',
    data: data
  })
}

// 删除测试样例
export function delMateri(id) {
  return request({
    url: '/result/materi/' + id,
    method: 'delete'
  })
}

// 查询所处县市列表
export function listCounty(query) {
  if(!query){
    query = new Object();
    query.fscope = "所在县市区";
  }

  return request({
    url: '/result/datadic/list',
    method: 'get',
    params: query
  })
}


// 查询数据字典项
export function listDataDic(query) {
  if(!query){
    query = new Object();
    query.fcode = "-1";
  }

  return request({
    url: '/result/datadic/list',
    method: 'get',
    params: query
  })
}

export function getImportLog(query){
  return request({
    url: '/result/materi/getimportlog',
    method: 'get',
    params: query
  })
}


/**
 * 生成guid
 * @returns {string}
 */
export function guid() {
  return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
  });
}

export function uploadHospital(fileobj){
  return request({
    method: 'post',
    url: '/result/materi/importMateri',
    headers: { 'Content-Type': 'multipart/form-data' }, // 设置响应头
    data: fileobj
  })
}
